<!-- 拒保弹框 -->
<template>
    <div>
        <el-dialog v-model="showDialog" title="拒保理由" width="515">
            <el-input v-model="jbtextarea" maxlength="100" placeholder="请输入拒保理由" show-word-limit type="textarea" />
            <div class="flexcenterbox" style="margin-top: 40px">
                <el-button class="my_cancelbtn" @click="longrejectcancel">取消</el-button>
                <el-button class="my_btn" @click="longrejectsure">确定</el-button>
            </div>
        </el-dialog>
    </div>
</template>
<script lang="ts" setup>
import { ref, watch } from 'vue'
import {
    ElMessage,
} from 'element-plus'

import {
    longdispatchingagencycheckapi,
} from '@/api/api'

const props = defineProps({
    show: {
        type: Boolean,
        default: false
    },
    itemDetail: {
        type: Object,
        default() {
            return {}
        }
    }
})

const emits = defineEmits(['update:show', 'success'])

const showDialog = ref(false)

const jbtextarea = ref('')

const longrejectcancel = () => {
    jbtextarea.value = ''
    showDialog.value = false
}

const longrejectsure = () => {
    if (jbtextarea.value === '') {
        ElMessage.error('请输入拒保理由.')
        return
    }
    longdispatchingagencycheck()
}

const longdispatchingagencycheck = async () => {
    const query = {
        id: props.itemDetail.id,
        serveCompanyName: props.itemDetail.serveCompanyName,
        companyId: props.itemDetail.companyId,
        companyName: props.itemDetail.companyName,
        serveCompanyId: props.itemDetail.serveCompanyId,
        status: 3,
        occupationIds: props.itemDetail.occupationIds,
        remark: jbtextarea.value,
    }
    const res: any = await longdispatchingagencycheckapi(query)
    if (res.code === 200) {
        ElMessage({
            message: res.msg,
            type: 'success',
        })
        emits('success')
        longrejectcancel()
    }
}

watch(() => props.show, (newval) => {
    showDialog.value = newval
})

watch(showDialog, (newval) => {
    emits('update:show', newval)
})
</script>
<style lang="scss" scoped></style>